package ipad.asia.controller;

import ipad.asia.entity.Discount;
import ipad.asia.entity.Product;
import ipad.asia.service.DiscountService;
import ipad.asia.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DiscountController {
    @Autowired
    private DiscountService discountService;
    //折扣
    @RequestMapping("/setDiscount/discount/")
    public void setDiscount(@RequestParam(value = "productId",required = false) String productId,
                         @RequestParam(value = "setDiscount",required = false)String setDiscount){
        discountService.SetDiscount(Integer.parseInt(productId),Float.parseFloat(setDiscount));
    }
    //降价
    @RequestMapping("/setDiscount/reduce")
    public void setReduce(@RequestParam(value = "productId",required = false) String productId,
                          @RequestParam(value = "reduce",required = false)String reduce){
        discountService.SetReduce(Integer.parseInt(productId),Float.parseFloat(reduce));
    }
    //秒杀
    @RequestMapping("/setDiscount/secKill")
    public void setSecKill(@RequestParam(value = "productId",required = false) String productId,
                           @RequestParam(value = "secKill",required = false)String secKill){
        discountService.SetSecKill(Integer.parseInt(productId),Float.parseFloat(secKill));
    }
    //优惠券
    @RequestMapping("/setDiscount/Coupon")
    public void setCoupon(@RequestParam(value = "productId",required = false) String productId,
                          @RequestParam(value = "coupon",required = false)String coupon){
        discountService.SetCoupon(Integer.parseInt(productId),Float.parseFloat(coupon));

    }
    //删除优惠
    @RequestMapping("/delDiscount")
    public void delDiscount(@RequestParam(value = "productId",required = false) String productId){
        discountService.delDiscount(Integer.parseInt(productId));
        System.out.println("yes");
    }
    //查询当前商品优惠优惠
    @RequestMapping("/findDiscount/{productId}")
    public Discount findDiscount(@PathVariable(value = "productId",required = false) int productId){
       return discountService.findDiscount(productId);
    }
}
